//
//  APHomeBallAlertView.m
//  AqualPolo
//
//  Created by dong on 2024/5/14.
//

#import "APHomeBallAlertView.h"

@implementation APHomeBallAlertView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.cornerRadius = 8;
        self.layer.masksToBounds = true;
        self.layer.borderWidth = 2;
        self.layer.borderColor = LYRGBColor(87, 61, 255).CGColor;
        
        UIImageView *bgImageView = [[UIImageView alloc] init];
        bgImageView.image = [UIImage imageNamed:@"home_alert_bg"];
        bgImageView.contentMode = UIViewContentModeScaleAspectFill;
        bgImageView.layer.masksToBounds = true;
        [self addSubview:bgImageView];
        
        UIView *contentView = [[UIView alloc] init];
        [self addSubview:contentView];
        [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        
        UIImageView *ballBackgroundImageView = [[UIImageView alloc] init];
        ballBackgroundImageView.image = [UIImage imageNamed:@"home_ball_bg"];
        [contentView addSubview:ballBackgroundImageView];
        [ballBackgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(contentView).offset(7);
            make.centerX.equalTo(contentView);
            make.size.mas_equalTo(CGSizeMake(98, 98));
        }];
        
        _ballImageView = [[UIImageView alloc] init];
        [ballBackgroundImageView addSubview:_ballImageView];
        [_ballImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(ballBackgroundImageView);
            make.size.mas_equalTo(CGSizeMake(60, 60));
        }];
        
        _ballNameLabel = [[UILabel alloc] init];
        _ballNameLabel.textColor = LYRGBColor(248, 255, 255);
        _ballNameLabel.font = [LYFont fontWithSize:18 fontName:LYFontNamepfb];
        _ballNameLabel.textAlignment = NSTextAlignmentCenter;
        [contentView addSubview:_ballNameLabel];
        [_ballNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_ballImageView.mas_bottom).offset(15);
            make.height.mas_equalTo(20);
            make.left.right.equalTo(contentView);
        }];
        
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.textColor = LYRGBAColor(255, 255, 255, 0.6);
        _contentLabel.numberOfLines = 0;
        _contentLabel.lineBreakMode = NSLineBreakByCharWrapping;
        [_contentLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
        [_contentLabel setContentCompressionResistancePriority:UILayoutPriorityFittingSizeLevel forAxis:UILayoutConstraintAxisVertical];
        _contentLabel.font = [LYFont fontWithSize:15 fontName:LYFontNamepfr];
        _contentLabel.textAlignment = NSTextAlignmentLeft;
        [contentView addSubview:_contentLabel];
        [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_ballNameLabel.mas_bottom).offset(16);
            make.left.equalTo(contentView).offset(16);
            make.right.equalTo(contentView).offset(-16);
        }];
        
        _clickButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _clickButton.backgroundColor = LYRGBColor(87, 61, 255);
        _clickButton.layer.cornerRadius = 8;
        _clickButton.layer.masksToBounds = true;
        _clickButton.layer.shadowColor = LYRGBColor(68, 45, 220).CGColor;
        _clickButton.layer.shadowOffset = CGSizeMake(2, 2);
        _clickButton.layer.shadowRadius = 8;
        _clickButton.layer.shadowOpacity = 1;
        _clickButton.titleLabel.font = [LYFont fontWithSize:18 fontName:LYFontNamepfb];
        [_clickButton setTitle:@"OK" forState:UIControlStateNormal];
        [contentView addSubview:_clickButton];
        [_clickButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_contentLabel.mas_bottom).offset(32);
            make.width.mas_equalTo(125);
            make.height.mas_equalTo(48);
            make.centerX.equalTo(contentView);
        }];
        
        _bubbleView = [[APHomeBallAlertBubbleView alloc] init];
        _bubbleView.hidden = true;
        [contentView addSubview:_bubbleView];
        [_bubbleView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_clickButton.mas_top).offset(5);
            make.right.equalTo(_clickButton);
            make.size.mas_equalTo(CGSizeMake(55, 25));
        }];
        
        _msgLabel = [[UILabel alloc] init];
        _msgLabel.textColor = LYRGBColor(154, 255, 213);
        _msgLabel.font = [LYFont fontWithSize:10 fontName:LYFontNamepfr];
        _msgLabel.textAlignment = NSTextAlignmentCenter;
        _msgLabel.numberOfLines = 0;
        [contentView addSubview:_msgLabel];
        [_msgLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_clickButton.mas_bottom).offset(16);
            make.left.equalTo(contentView).offset(16);
            make.right.equalTo(contentView).offset(-16);
            make.bottom.equalTo(contentView).offset(-24);
        }];
        
        [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(self);
        }];
        
    }
    return self;
}

@end


@implementation APHomeBallAlertBubbleView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _imageView = [[UIImageView alloc] init];
        _imageView.image = [UIImage imageNamed:@"buy_bubble_bg"];
        [self addSubview:_imageView];
        [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        
        _coinImageView = [[UIImageView alloc] init];
        _coinImageView.image = [UIImage imageNamed:@"coin_icon_s"];
        [self addSubview:_coinImageView];
        [_coinImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(9);
            make.top.equalTo(self).offset(3);
            make.size.mas_equalTo(CGSizeMake(14, 14));
        }];
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.text = @"99";
        _titleLabel.textColor = LYRGBColor(87, 61, 255);
        _titleLabel.font = [LYFont fontWithSize:10 fontName:LYFontNamepfr];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_coinImageView.mas_right).offset(4);
            make.centerY.equalTo(_coinImageView);
        }];
    }
    return self;
}

@end
